//package com.ican.config;
//
//import co.elastic.clients.elasticsearch.ElasticsearchClient;
//import co.elastic.clients.json.jackson.JacksonJsonpMapper;
//import co.elastic.clients.transport.ElasticsearchTransport;
//import co.elastic.clients.transport.rest_client.RestClientTransport;
//import org.apache.http.HttpHost;
//import org.apache.http.auth.AuthScope;
//import org.apache.http.auth.UsernamePasswordCredentials;
//import org.apache.http.client.CredentialsProvider;
//import org.apache.http.impl.client.BasicCredentialsProvider;
//import org.elasticsearch.client.RestClient;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
///**
// * Elasticsearch配置
// *
// * @author ican
// */
//@Configuration
//public class ElasticsearchConfig {
//
//    @Value("${elasticsearch.username}")
//    private String username;
//
//    @Value("${elasticsearch.password}")
//    private String password;
//
//    @Value("${elasticsearch.hostname}")
//    private String hostname;
//
//    @Value("${elasticsearch.port}")
//    private int port;
//
//    @Value("${elasticsearch.scheme}")
//    private String scheme;
//
//    @Value("${elasticsearch.connTimeout}")
//    private int connTimeout;
//
//    @Value("${elasticsearch.socketTimeout}")
//    private int socketTimeout;
//
//    @Value("${elasticsearch.connectionRequestTimeout}")
//    private int connectionRequestTimeout;
//
//    @Bean
//    public ElasticsearchClient elasticsearchClient() {
//        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
//        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
//        RestClient restClient = RestClient.builder(new HttpHost(hostname, port, scheme))
//                .setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder
//                        .setConnectTimeout(connTimeout)
//                        .setSocketTimeout(socketTimeout)
//                        .setConnectionRequestTimeout(connectionRequestTimeout)
//                ).setHttpClientConfigCallback(f -> f.setDefaultCredentialsProvider(credentialsProvider)).build();
//        ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
//        return new ElasticsearchClient(transport);
//    }
//}
